import 'package:cbec_app/components/decoration/DecorationCoupon/special_dividing_line.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';

class BigMode extends StatelessWidget {
  // 整体背景颜色
  final Color couponColor;

  // 价格 的颜色
  final Color priceColor;

  // 名称的颜色
  final Color nameColor;

  // 描述 颜色
  final Color secondaryColor;

  // 半圆颜色
  final Color halfCircleColor;

  // 分割线颜色
  final Color lineColor;

  // 领取 颜色
  final Color claimColor;

  final String text;

  final String unit;

  final String name;

  final String desc;

  final VoidCallback? callback;

  final bool? showDivideLine;

  final bool? haveBg;

  const BigMode({
    super.key,
    required this.couponColor,
    required this.priceColor,
    required this.nameColor,
    required this.secondaryColor,
    required this.halfCircleColor,
    required this.lineColor,
    required this.claimColor,
    required this.text,
    required this.unit,
    required this.name,
    required this.desc,
    this.callback,
    this.showDivideLine = false,
    this.haveBg = false,
  });

  @override
  Widget build(BuildContext context) {
    final width = ScreenUtil().screenWidth - 16;
    const height = 95.0;
    const leftWidth = 95.0;
    const rightWidth = 95.0;
    final middleWidth = width - leftWidth - rightWidth;

    return Container(
      color: couponColor,
      width: width,
      height: height,
      child: haveBg == true ? _buildWithBackground(leftWidth, middleWidth, rightWidth) : _buildWithoutBackground(leftWidth, middleWidth, rightWidth),
    );
  }

  Widget _buildWithBackground(double leftWidth, double middleWidth, double rightWidth) {
    return Row(
      children: [
        Container(
          color: Colors.white,
          height: 80,
          margin: const EdgeInsets.only(left: 8, top: 8, bottom: 8),
          width: leftWidth + middleWidth - 8,
          child: Row(
            children: [
              _buildLeftSection(leftWidth - 8),
              _buildMiddleSection(middleWidth),
            ],
          ),
        ),
        _buildRightSection(rightWidth, () {
          if (callback != null) {
            callback!();
          }
        }),
      ],
    );
  }

  Widget _buildWithoutBackground(double leftWidth, double middleWidth, double rightWidth) {
    return Row(
      children: [
        _buildLeftSection(leftWidth),
        _buildMiddleSection(middleWidth),
        const Spacer(),
        if (showDivideLine == true) SpecialDividingLine(painterColor: halfCircleColor, lineColor: lineColor),
        _buildRightSection(showDivideLine == true ? rightWidth - 10 : rightWidth, () {
          if (callback != null) {
            callback!();
          }
        }),
      ],
    );
  }

  Widget _buildLeftSection(double width) {
    return SizedBox(
      width: width,
      child: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              text,
              style: TextStyle(color: priceColor, fontSize: 20, fontWeight: FontWeight.bold),
            ),
            Text(
              unit,
              style: TextStyle(color: priceColor, fontSize: 10, fontWeight: FontWeight.normal),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildMiddleSection(double width) {
    return SizedBox(
      width: width,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            name,
            style: TextStyle(color: nameColor),
          ),
          Text(
            desc,
            style: TextStyle(color: secondaryColor, fontWeight: FontWeight.normal, fontSize: 10),
          ),
        ],
      ),
    );
  }

  Widget _buildRightSection(double width, VoidCallback onTap) {
    return SizedBox(
      width: width,
      child: TextButton(
        onPressed: onTap,
        child: Text(
          '领取',
          style: TextStyle(color: claimColor, fontWeight: FontWeight.normal, fontSize: 13),
        ),
      ),
    );
  }
}
